#ifndef _LED_H_
#define _LED_H_

#include "driver/gpio.h"
#include <mutex>
#include "esp_timer.h"

#define EN_LED_BRIGHTNESS_ADJUST    0   // 是否支持调节亮度
#define TIMER_TYPE ""                   // 使用的定时器类型

class Led {
public:
    Led(gpio_num_t gpio, bool common_anode = true);
    ~Led();

    virtual void BlinkOnce();
    virtual void Blink(int times, int interval_ms);
    virtual void StartContinuousBlink(int interval_ms);
    virtual void TurnOn();
    virtual void TurnOff();
#ifdef LED_BRIGHTNESS_ADJUST
    virtual void SetBrightness(uint8_t brightness);
#endif
private:
    std::mutex  m_mutex;        // 互斥锁，防止线程对资源同时进行操作
    gpio_num_t  m_led;                      // LED 引脚
    bool        m_common_anode = true;      // 是否为共阳极
    bool        m_continuous_blink = false; // 是否连续闪烁
    int         m_blink_times;              // 闪烁次数
    int         m_interval_ms;              // 闪烁间隔
#ifdef LED_BRIGHTNESS_ADJUST
    uint8_t     m_brightness;               // 亮度
#endif
    esp_timer_handle_t m_timer_handle;      // 定时器句柄

    void LedTimerCallback();
};



#endif